// pages/informant/informant.js
var util = require("../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    InformantCase: [],
    selectedCase: '',
    box_id: '1',
    data: {
      hidden: true, //等待的展示与隐藏的控制
      buthidden: false //按钮的可用和不可用的控制
    }
  },
  radioChange: function (e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      box_id: options.box_id,
      box_bn: options.box_bn
    })
    var that = this;
    // 获取故障列表
    const requestInformantCase = wx.request({
      url: "https://boxapi.supergk.com/server/box/stained_list",
      success: function (res) {
        console.log(res.data.data)
        if (res.data.code == 0) {
          that.setData({
            InformantCase: res.data.data
          })
        } else {
          console.log(res.msg)
        }
      }
    })
  },

  bindTextAreaBlur: function (e) {
    this.setData({
      informantIntro: e.detail.value
    })
  },
  formSubmit: function (e) {
    var that = this;
    this.setData({
      hidden: false,
      buthidden: true
    })
    console.log(e.detail.value)
    var that = this;
    var formData = e.detail.value;
    var _uid = wx.getStorageSync("userInfo").userInfo.uid;
    var box_id = that.data.box_id;
    if (formData.reason == "") {
      wx.showToast({
        title: '请选择原因',
        icon: 'loading'
      })
    } else {
      wx.request({
        url: 'https://boxapi.supergk.com/server/box/save_box_stained',
        data: util.json2Form({ box_id: box_id, submitter_id: _uid, submitter_type: '1', stain_types: formData.reason, content: formData.content }),
        header: {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        method: "POST",
        success: function (res) {
          console.log(res.data)
          if (res.data.code == 0) {
            that.setData({
              hidden: false,
              buthidden: true
            })
            wx.showToast({
              title: '举报成功',
              icon: 'success'
            })
            setTimeout((function callback() {
              wx.navigateTo({
                url: '../index/index',
              })
            }).bind(this), 1000);
          } else {
            that.setData({
              hidden: true,
              buthidden: false
            })
            console.log(res.data.msg)
            util.showModel('提示', res.data.msg)
          }
        }
      })
    }

  },
  // informantSubmit: function () {
  //   var _uid = wx.getStorageSync("userInfo").userInfo.uid;

  //   const requestInformantCase = wx.request({
  //     url: "https://boxapi.supergk.com/server/box/save_box_stained",
  //     data: util.json2Form({
  //       box_id: this.data.box_id,
  //       submitter_id: "uid",
  //       submitter_type: "1",
  //       stain_types: this.data.selectedCase,
  //       content: thid.data.informantIntro
  //     }),
  //     header: {
  //       "Content-Type": "application/x-www-form-urlencoded"
  //     },
  //     success: function (res) {
  //       console.log(res.data.data)
  //       if (res.data.code == 0) {
  //         wx.showToast({
  //           title: '举报成功',
  //           icon: 'success'
  //         })
  //       } else {
  //         console.log(res.msg)
  //       }
  //     }
  //   })
  // },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    wx.setNavigationBarTitle({
      title: '污损举报',
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})